package com.gp.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gp.common.result.JsonResult;
import com.gp.common.utils.StringUtil;
import com.gp.exception.ExceptionInfo;

/**
 * @author: 弓成龙
 * @date  : 2017年12月11日
 * @email : gcx909109@sina.cn
 * @description: 
 */
@Controller
public class MenuController {
  
  @ResponseBody
  @RequestMapping("/error")
  public JsonResult error(HttpServletRequest request) {
    String detail = (String) request.getAttribute("detail");
    String message = (String) request.getAttribute("message");
    String happenTime = StringUtil.obtinDateStr(null);
    ExceptionInfo ei = new ExceptionInfo(happenTime,message,detail);
    // 此处可以将异常存储到数据库中，等待管理员进行检查修复，这里输出到控制台，服务端进行处理
    StringBuilder sb = new StringBuilder();
    sb.append("\n\n!!!error_start!!!");
    sb.append("\nmessage   :" + message);
    sb.append("\nhappenTime:" + happenTime);
    sb.append("\ndetail    :" + detail);
    sb.append("\n!!!error_end!!!\n");
    LoggerFactory.getLogger(MenuController.class).error(sb.toString());
    return new JsonResult(500,ei);
  }
}

